Skip to content

docs(observability/metrics): document the metrics package#158

Open
xytan0056 wants to merge 1 commit into
mainfrom
pr0-docs
Open

docs(observability/metrics): document the metrics package#158
xytan0056 wants to merge 1 commit into
mainfrom
pr0-docs

Conversation

@xytan0056

@xytan0056 xytan0056 commented Jul 7, 2026

Copy link
Copy Markdown
Contributor

add Tango Metrics Inventory RFC into the repo. Covers the Emitter contract, metrics invetnory, context propagation design and other utils and their usage.

@xytan0056 xytan0056 force-pushed the pr0-docs branch 5 times, most recently from ea9e0ef to d01c936 Compare July 7, 2026 23:37
@xytan0056 xytan0056 marked this pull request as ready for review July 7, 2026 23:39
@xytan0056 xytan0056 requested review from a team as code owners July 7, 2026 23:39
- shared metric-name, op-name, and tag-key constants
- default histogram buckets sized for RPC latency and large target counts
- an in-flight gauge helper that owns the atomic counter callers otherwise reinvent
- a failure classifier that reuses the errors package

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@justinwon777 place holder for errors package design RFC

@xytan0056 xytan0056 force-pushed the pr0-docs branch 3 times, most recently from f8b5223 to a1249f6 Compare July 7, 2026 23:52
Ports the Tango Metrics Inventory RFC into the repo. Covers the
Emitter contract, buckets, TrackInFlight, RecordFailure, context
propagation, shared constants, and OSS / internal / CLI usage.

## Emitter

`Emitter` is an interface. `New(scope)` returns the default tally-backed implementation; `New(nil)` returns one backed by `tally.NoopScope` so callers do not need to special-case unwired metrics. This also serves as a noop fallback.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
`Emitter` is an interface. `New(scope)` returns the default tally-backed implementation; `New(nil)` returns one backed by `tally.NoopScope` so callers do not need to special-case unwired metrics. This also serves as a noop fallback.
`Emitter` is an interface. `New(scope)` returns the default tally-backed implementation; `New(nil)` returns one backed by `tally.NoopScope` so callers do not need to special-case metrics using alternative metrics library than tally. This also serves as a no-op fallback which could be useful for things like tests.

Comment on lines +51 to +55
`New(scope)` returns the default tally-backed implementation; `New(nil)` returns one backed by `tally.NoopScope` so callers do not need to special-case unwired metrics.

`Tagged` returns a child Emitter that adds tags to every subsequent emission. The parent is unchanged. The child shares the in-flight counter map, so a `TrackInFlight` increment on a parent and its decrement on a tagged child balance to zero.

Options are variadic and compose. `WithTags` merges into the base tag set with later-wins semantics on key collision. `WithDurationBuckets` / `WithValueBuckets` override the emitter's default histogram buckets on a single call.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can this section be written as a docstring with func signature?

// New returns the default Tally-backed Emitter implementation.
func New(scope tally.Scope) Emitter 

// and so on... 


Options are variadic and compose. `WithTags` merges into the base tag set with later-wins semantics on key collision. `WithDurationBuckets` / `WithValueBuckets` override the emitter's default histogram buckets on a single call.

## Op-as-subscope

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what does this mean??


Every emit call takes an op name as its first argument. `e.Inc("get_target_graph", "requests")` emits under `<scope>.get_target_graph.requests`. Consumers that own their own ops (an extension RPC, a background job) should declare `const opXYZ = "xyz"` next to the emit site rather than adding to `names.go`.

## TrackInFlight

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same thing here, let's make this into an API form.


Every RPC calls one of:

- `e.Inc(op, Requests, WithTags({result: success}))` on the happy path

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Inc and RecordFailure aren't intuitive names for counterparts of each other. can we rename?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also, not sure why is Inc and failure/success is a thing. Do we need this?


## Constants

All shared constants live in `names.go`: operation names (`OpGetTargetGraph`, `OpGetChangedTargets`, ...), metric names (`Requests`, `TotalDuration`, `InFlightRequests`, ...), tag keys (`TagRepo`, `TagEmitter`, `TagResult`, `TagFailureType`, `TagFailureSource`, ...), and `Result*` values (`ResultSuccess`, `ResultFail`, `ResultHit`, `ResultMiss`).

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

where they live isn't relevant to this RFC.

Can we make this into a table form?

@xytan0056 xytan0056 force-pushed the pr0-docs branch 2 times, most recently from 32c02ad to cf7326b Compare July 8, 2026 18:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants